package dataStructure.study.sort;

/**
 * Author: shangsf
 * Date: 2021/4/6 22:22
 * Description:冒泡排序，时间复杂度O(n^2)
 */
public class BubbleSort {

    public static void sort(int[] array){
        if(array==null||array.length==1){
            return;
        }
        int n=array.length;
        for(int i=0;i<n;i++){
            for (int j=0;j<n-i-1;j++){
                if(array[j]>array[j+1]){
                    int tmp=array[j];
                    array[j]=array[j+1];
                    array[j+1]=tmp;
                }
            }
        }
    }
}
